layui.extend({
    baseConfig : "/js/pages/baseConfig"
})
layui.use(['form','layer','laydate','table','laytpl','baseConfig'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        baseConfig = layui.baseConfig,
        $ = layui.jquery;

    //设置编辑表单里面的用户信息
    var userInfo = JSON.parse( window.sessionStorage.getItem( "userInfo"));
    $("input[name=jobNumber]").val( userInfo.jobNumber);

    //添加验证规则
    form.verify({
        oldPwd : function(value, item){
            if( hex_md5( value) != userInfo.password){
                return "密码错误，请重新输入！";
            }
        },
        newPwd : function(value, item){
            if(value.length < 6){
                return "密码长度不能小于6位";
            }
        },
        confirmPwd : function(value, item){
            if(!new RegExp($("#oldPwd").val()).test(value)){
                return "两次输入密码不一致，请重新输入！";
            }
        }
    });

    //修改密码
    form.on("submit(changePassword)",function(data){
        var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.post("/adminUser/changePassword",{
            'jobNumber' : data.field.jobNumber,
            'oldPassword' : hex_md5( data.field.oldPassword),
            'newPassword' : hex_md5( data.field.newPassword)
        },function( res){
            if( res.code == 200){
                top.layer.msg( res.msg);
                layer.close( index);
                layer.closeAll( "iframe");
            }else{
                top.layer.msg( res.msg);
            }
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    })
})
